package com.alotus.util.common;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

/**
 * 基础Controller,获得writeJson功能
 * 
 * @version $Id: BaseAction.java, v 0.1 $
 * @author silence.cheng
 * 2016年6月10日 上午10:55:12
 */
public class BaseController<T>{
	
	private static final Logger logger = Logger.getLogger(BaseController.class);
	protected int page = 1;// 当前页
	protected int rows = 10;// 每页显示记录数
	protected String sort;// 排序字段
	protected String order = "asc";// asc/desc

	protected String id;// 主键
	protected String ids;// 主键集合，逗号分割
	
	
	/**
	 * 封装JSON字符串
	 * 
	 * @param object
	 * @throws IOException
	 * @errorType 自定义错误返回类型
	 */
	public HashMap<String, Object> pakeageJson(Object data) {
		HashMap<String, Object> jsonMap=new HashMap<String, Object>();
		if (data!=null) {
			jsonMap.put("success",true);
			jsonMap.put("errorType",Const.SUCCESS_FLAG);
			jsonMap.put("msg","查询数据成功");
			jsonMap.put("data", data);
		}else{
			jsonMap.put("success",false);
			jsonMap.put("errorType",Const.ERROR_FLAG);
			jsonMap.put("msg","查询数据失败:");
		}
		return jsonMap;
		
	}
	public HashMap<String, Object> pakeageJson(Object data,String msg) {
		HashMap<String, Object> jsonMap=new HashMap<String, Object>();
		if (data!=null) {
			jsonMap.put("success",true);
			jsonMap.put("errorType",Const.SUCCESS_FLAG);
			jsonMap.put("msg","查询数据成功");
			jsonMap.put("data", data);
		}else{
			jsonMap.put("success",false);
			jsonMap.put("errorType",Const.ERROR_FLAG);
			jsonMap.put("msg","查询数据失败:"+msg);
		}
		return jsonMap;
		
	}
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}


}
